home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / diskutil / rde_v5.zoo / desktop2.zoo / desktop2.c next >
Encoding:
C/C++ Source or Header  |  1993-08-27  |  5.0 KB  |  198 lines

  1. /*    DESKTOP2.PRG Program           by W. Alan B. Evans,
  2.                        [wabe@ukc.ac.uk]  March 1992.
  3.  
  4.    If put in AUTO-FOLDER of "booting" RDY-ramdisk will ensure that any
  5. DESKTOP.INF file in the ramdisk's root directory will be copied to C:\
  6. (if C:\ exists) where the newer TOS-Versions will look for it.
  7.  
  8.    With TOS 2.06 NEWDESK.INF (or DESKTOP.INF) should be copied to
  9. C:\NEWDESK.INF and this is now done in the DESKTOP2.PRG (Version_2? of
  10. DESKTOP.PRG). The TOS Version is also printed out - and it is still smaller
  11. than 2048 bytes so will only pinch 2 clusters of your ramdisk!!
  12.                         wabe    May 1993.
  13. */
  14.  
  15. #include <osbind.h>
  16.  
  17. #define        TOSPTR        (*(unsigned short **)0x4f2)
  18.  
  19. extern    char *strcpy(),*gts();
  20.  
  21. main()
  22.  
  23. {    long st;    char file[60];
  24.     unsigned short tos;    char *itoa();
  25.  
  26. /*   This is escape from "BOOT & WARMSTART" loop caused by faulty ACC's etc.
  27.      since it enables one to invoke a simple non-GEM shell e.g ME.TOS,
  28.      COMMAND.PRG, RDYSH.PRG or GULAM.PRG etc. to rename the offending ACC
  29.      or boot program
  30. */
  31.     if (Cconis()== -1 && (Crawcin() & 0x5f) == 'X') {
  32.     Cconws("\r\n  FULL PATH\\NAME OF PROGRAM TO BE EXECUTED: ");
  33.     Pexec(0,gts(file),"\0","\0");
  34.     }
  35.  
  36. /*   Get Tos_Version    */
  37.     st= Super(0L);
  38.     tos = *(TOSPTR+1);
  39.     Super(st);
  40.  
  41. /*   Might as well print it out            */
  42.     Cconws("\r\n  Tos_Version = \033p"); Cconws(itoa(tos >> 8,file,16));
  43.     Cconout('.'); if ((tos & 0x00FF) < '\020') Cconout('0');
  44.     Cconws(itoa((tos & 0x00FF),file,16));    Cconws("\033q\r\n");
  45.  
  46.     if ((long)Drvmap() & 04L)
  47.     if (tos >= 0x104)      /*  STE TOS Present!    */
  48. /*  Ensure the proper DESKTOP.INF file is looked at by new TOS  */
  49.     { if (tos < 0x200)
  50.     st= fc("DESKTOP.INF\0","C:\\DESKTOP.INF\0");
  51.     else    if (st= fc("NEWDESK.INF\0","C:\\NEWDESK.INF\0"))
  52.         st= fc("DESKTOP.INF\0","C:\\NEWDESK.INF\0");
  53.     }
  54. /*  Execute the 40-Folder Patch Prog if found on C:\ with old TOS  */
  55.     else  Pexec(0,"C:\\FOLDR???.PRG\0","\0","\0");
  56.  
  57. Pterm(st);
  58. }
  59.  
  60.  
  61. /*
  62. *   A useful File_Copying subroutine - preserves date_stamp on old TOS  
  63. */
  64.  
  65. int fc(file1,file2)
  66. char *file1,*file2;
  67.  
  68. {    register char *buf;
  69.     int i,handle1,handle2,nsects,nsecmax,erc,no_tms,info[2];
  70.     long lo,nrw,flngth;
  71.  
  72.     erc= 0;    buf= 0;
  73.     if ((nsecmax = (int)(Malloc(-1L)/0x200L)-4) < 0)
  74.     { gemdos(9,"\r\n  INSUFFICIENT MEMORY!! ");  goto end;    }
  75.  
  76.     if ((handle1 = Fopen(file1,0)) < 0) return(-1);
  77.     Fdatime(info,handle1,0);
  78.     flngth= Fseek(0L,handle1,2);
  79.     nsects= 1+(int)(flngth/0x200L);
  80.     if ((no_tms= nsects/nsecmax) == 0) nsecmax= nsects;
  81.  
  82.     if ((handle2 = Fopen(file2,0)) > 0)
  83.     { Fclose(handle2); Fdelete(file2);    }
  84.     if ((handle2 = Fcreate(file2,0)) < 0 )
  85.     { gemdos(9,"\r\n Fcreate FAILURE - COULD NOT OPEN FILE: ");
  86.     gemdos(9,file2);    --erc; goto end; }
  87.  
  88.     if ((buf= (char *)Malloc((long)nsecmax*0x200L+0x200L)) == 0)
  89.     { gemdos(9,"\r\n Malloc FAILURE!!! "); --erc; goto end; }
  90.     Cconws("\r  Copying "); Cconws(file1);
  91.     Cconws(" to "); Cconws(file2);  Cconws("\r\n ");
  92.     i=-1; while (i++ < no_tms)
  93.     { if (i == no_tms) nrw= flngth- (long)nsecmax*0x200L*i;
  94.     else  nrw= (long)nsecmax*0x200;
  95.  
  96.     { if ((lo= Fseek((long)nsecmax*0x200L*i,handle1,0) < 0) 
  97.     || (lo=Fread(handle1,nrw,buf)) != nrw)
  98.     { gemdos(9,"\r\n Fseek or Fread FAILURE");  --erc; goto end;    }
  99.     }
  100.  
  101.     { if ((lo= Fseek((long)(nsecmax*0x200L*i),handle2,0) < 0) 
  102.     || (lo= Fwrite(handle2,nrw,buf)) != nrw)
  103.     { gemdos(9,"\r\n Fseek or Fwrite FAILURE!  DISK FULL? "); --erc; goto end; }
  104.     }
  105.     }    /*  end of i loop  */
  106.  
  107. end:    if (!Fclose(handle2))
  108.     { if (erc < 0) Fdelete(file2); else
  109.     { handle2=Fopen(file2,0); Fdatime(info,handle2,1); Fclose(handle2); }
  110.     }
  111.     if (buf != 0) Mfree(buf);
  112. return(erc);
  113. }
  114.  
  115.  
  116. /*
  117.         Cheap & minimal gets alternative
  118.     (  An economical alternative to "gets" - does not, however
  119.      respond to CNTRL-C on the Older TOSes    )
  120. */
  121. char *gts(data)
  122. char *data;
  123. {    register char *p = data;
  124.     while ((*p=gemdos(1)) != '\r')
  125.     if (*p == '\010') { --p; Cconws(" \010"); } else p++;
  126.     *p= '\0';
  127.     if (*data)    return(data);    else    return((char *)0);
  128. }
  129.  
  130. /*   Some code, pinched from Sozobon, for converting numbers to asci
  131.      & used above to print out the TOS Version - it is extremely economical
  132. */
  133.  
  134. char    _numstr[] = "0123456789ABCDEF";
  135.  
  136. char *ultoa(n, buffer, radix)
  137.     register unsigned long n;
  138.     register char *buffer;
  139.     register int radix;
  140.     {
  141.     register char *p = buffer;
  142.     char *strrev();
  143.  
  144.     do
  145.         {
  146.         *p++ = _numstr[n % radix];    /* grab each digit */
  147.         }
  148.         while((n /= radix) > 0);
  149.     *p = '\0';
  150.     return(strrev(buffer));            /* reverse and return it */
  151.     }
  152.  
  153. char *ltoa(n, buffer, radix)
  154.     register long n;
  155.     register char *buffer;
  156.     int radix;
  157.     {
  158.     register char *p = buffer;
  159.  
  160.     if (n < 0)
  161.         {
  162.         *p++ = '-';
  163.         n = -n;
  164.         }
  165.     ultoa(n, p, radix);
  166.     return(buffer);
  167.     }
  168.  
  169. char *itoa(n, buffer, radix)
  170.     int n;
  171.     char *buffer;
  172.     int radix;
  173.     {
  174.     char *ltoa();
  175.  
  176.     return(ltoa(((long) n), buffer, radix));
  177.     }
  178.  
  179.  
  180. char *strrev(string)
  181.     char *string;
  182.     {
  183.     register char *p = string, *q, c;
  184.  
  185.     if(*(q = p))        /* non-empty string? */
  186.         {
  187.         while(*++q)
  188.             ;
  189.         while(--q > p)
  190.             {
  191.             c = *q;
  192.             *q = *p;
  193.             *p++ = c;
  194.             }
  195.         }
  196.     return(string);
  197.     }
  198.